package sparrowGui.components
{
	import flash.display.Sprite;
	
	import sparrowGui.components.item.ItemFactory;
	import sparrowGui.components.item.SListItem;
	import sparrowGui.i.IItemFactory;

	/**
	 * 带滚动条和列表组件的列表数据组件
	 * 
		var rls:ScrollList = new ScrollList();
		rls.update([11,22,33,44,55,66,77]);
		addChild(rls);
	 * 
	 * @author Pelephone
	 * @website http://cnblogs.com/pelephone
	 */
	public class ScrollList extends BaseUIComponent
	{
		private var scrollPan:ScrollPanel;
		private var _list:SRadioGroup;
		
		/**
		 * 构造滚动列表
		 * @param uiVars
		 * @param cellFactory 子项工厂，用于创建子项和子项皮肤，工厂里还有缓存的功能
		 */
		public function ScrollList(uiVars:Object=null,cellFactory:IItemFactory=null)
		{
			super(uiVars);
			
			scrollPan = newScrollPanel();
			_list = newList(cellFactory);
			
			scrollPan.source = _list.skin;
		}
		
		/**
		 * 创建滚动面板
		 * @return 
		 */
		protected function newScrollPanel():ScrollPanel
		{
			return  new ScrollPanel(skin);
		}
		
		/**
		 * 创建列表组件
		 * @param cellFactory
		 * @return 
		 */
		protected function newList(cellFactory:IItemFactory=null):SRadioGroup
		{
			cellFactory = cellFactory || new ItemFactory(SListItem,"richItem");
			var ls:SRadioGroup = new SRadioGroup(new Sprite(),cellFactory);
			ls.colNum = 1;
			return ls;
		}
		
		/**
		 * 返回列表组件
		 * @return 
		 */
		public function get list():SRadioGroup 
		{
			return _list;
		}
		
		/**
		 * 更新内容
		 * @param data
		 */
		public function update(data:Object):void
		{
			_list.update(data);
			scrollPan.activeScroll();
		}
		
		/**
		 * 是否自动改变滚动条位置
		 */
		public function get autoScroll():Boolean
		{
			return scrollPan.autoScroll;
		}
		
		/**
		 * @private
		 */
		public function set autoScroll(value:Boolean):void
		{
			scrollPan.autoScroll = value;
		}
		
		/**
		 * 自动显示隐藏纵向滚动条
		 */
		public function get autoVhidden():Boolean
		{
			return scrollPan.autoVhidden;
		}
		
		/**
		 * @private
		 */
		public function set autoVhidden(value:Boolean):void
		{
			scrollPan.autoVhidden = value;
		}
		
		/**
		 * 自动显示隐藏纵向滚动条
		 */
		public function get autoHhidden():Boolean
		{
			return scrollPan.autoHhidden;
		}
		
		/**
		 * @private
		 */
		public function set autoHhidden(value:Boolean):void
		{
			scrollPan.autoHhidden = value;
		}
		
		/**
		 * 被滚动的显示对象宽
		 * @return 
		 */
		public function get sourceWidth():Number
		{
			return scrollPan.sourceWidth;
		}
		
		/**
		 * 被滚动的显示对象高
		 * @return 
		 */
		public function get sourceHeight():Number
		{
			return scrollPan.sourceHeight;
		}
		
		override public function set width(value:Number):void
		{
			scrollPan.width = value;
		}
		
		override public function get width():Number
		{
			return scrollPan.height;
		}
		
		override public function getDefaultUIName():String
		{
			return "scrollList";
		}
		
		override public function dispose():void
		{
			_list.dispose();
			scrollPan.dispose();
		}
	}
}